<!DOCTYPE html>
<html>

<head>
  <title>管理员登录</title>
  <style>
    body {
      display: flex;
      justify-content: center;
      align-items: center;
      min-height: 100vh;
      background: #f5f7fa;
      font-family: "微软雅黑", sans-serif;
    }

    .login-box {
      background: white;
      padding: 30px 40px;
      border-radius: 12px;
      box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
    }

    h2 {
      text-align: center;
      margin-bottom: 30px;
      color: #1f2937;
      font-size: 1.5em;
      font-weight: 600;
    }

    .form-group {
      margin-bottom: 20px;
    }

    input {
      width: 100%;
      padding: 12px 15px;
      border: 1px solid #e0e0e0;
      border-radius: 6px;
      font-size: 0.95em;
      text-indent: 10px;
    }

    input:focus {
      outline: none;
      border-color: #1a73e8;
      box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.2);
    }

    button {
      width: 100%;
      padding: 14px;
      background: #1a73e8;
      color: white;
      border: none;
      border-radius: 6px;
      font-size: 1em;
      font-weight: 500;
      cursor: pointer;
      transition: background-color 0.3s;
    }

    button:hover {
      background-color: #1557b0;
    }

    .error {
      color: #dc2626;
      font-size: 0.9em;
      display: none;
      margin-top: 10px;
      text-align: center;
    }
  </style>
</head>

<body>
  <div class="login-box">
    <h2>管理员登录</h2>
    <form id="loginForm">
      <div class="form-group">
        <input type="text" id="username" placeholder="用户名" required autofocus>
      </div>
      <div class="form-group">
        <input type="password" id="password" placeholder="密码（8-20位，含大小写字母、数字和特殊字符）" required
          pattern="^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*])[a-zA-Z\d!@#$%^&*]{8,20}$"
          title="密码需包含大小写字母、数字和至少一个特殊字符（!@#$%^&*）">
      </div>
      <span class="error" id="loginError">用户名或密码错误</span>
      <button type="submit">登录</button>
    </form>
  </div>

  <script>
    document.getElementById('loginForm').addEventListener('submit', function (e) {
      e.preventDefault();
      const username = document.getElementById('username').value.trim();
      const password = document.getElementById('password').value.trim();
      const errorMsg = document.getElementById('loginError');

      // 模拟正确账号密码（包含特殊字符！）
      const validUser = { username: 'admin', password: 'Admin123!' };

      if (username === validUser.username && password === validUser.password) {
        localStorage.setItem('adminToken', 'Bearer valid-token-here');
        window.location.href = 'dashboard.html';
      } else {
        errorMsg.style.display = 'block';
        // 错误后清空输入框
        document.getElementById('username').value = '';
        document.getElementById('password').value = '';
      }
    });
  </script>
</body>

</html>